package com.ruoyi.binance.controller;

import com.ruoyi.binance.domain.BinancePriceMonitoring;
import com.ruoyi.binance.service.IBinancePriceMonitoringService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 日均价监控Controller
 *
 * @author zq
 * @date 2025-08-05
 */
@RestController
@RequestMapping("/binance/monitoring")
public class BinancePriceMonitoringController extends BaseController {
    @Autowired
    private IBinancePriceMonitoringService binancePriceMonitoringService;

    /**
     * 查询日均价监控列表
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:list')")
    @GetMapping("/list")
    public TableDataInfo list(BinancePriceMonitoring binancePriceMonitoring) {
        startPage();
        List<BinancePriceMonitoring> list = binancePriceMonitoringService.selectBinancePriceMonitoringList(binancePriceMonitoring);
        return getDataTable(list);
    }

    /**
     * 导出日均价监控列表
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:export')")
    @Log(title = "日均价监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BinancePriceMonitoring binancePriceMonitoring) {
        List<BinancePriceMonitoring> list = binancePriceMonitoringService.selectBinancePriceMonitoringList(binancePriceMonitoring);
        ExcelUtil<BinancePriceMonitoring> util = new ExcelUtil<BinancePriceMonitoring>(BinancePriceMonitoring.class);
        util.exportExcel(response, list, "日均价监控数据");
    }

    /**
     * 获取日均价监控详细信息
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code) {
        return success(binancePriceMonitoringService.selectBinancePriceMonitoringByCode(code));
    }

    /**
     * 新增日均价监控
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:add')")
    @Log(title = "日均价监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BinancePriceMonitoring binancePriceMonitoring) {
        int i = binancePriceMonitoringService.insertBinancePriceMonitoring(binancePriceMonitoring);
        return toAjax(i);
    }

    /**
     * 修改日均价监控
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:edit')")
    @Log(title = "日均价监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BinancePriceMonitoring binancePriceMonitoring) {
        return toAjax(binancePriceMonitoringService.updateBinancePriceMonitoring(binancePriceMonitoring));
    }

    /**
     * 删除日均价监控
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:remove')")
    @Log(title = "日均价监控", businessType = BusinessType.DELETE)
    @DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes) {
        return toAjax(binancePriceMonitoringService.deleteBinancePriceMonitoringByCodes(codes));
    }

    /**
     * 折线图
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('binance:monitoring:chart')")
    @GetMapping("/chart")
    public AjaxResult chart(String code, String startTime, String endTime) {
        return success(binancePriceMonitoringService.chart(code, startTime, endTime));
    }

    /**
     * 15MACD折线图
     *
     * @return
     */
    @GetMapping("/macd15")
    public AjaxResult macd15(String code, String startTime, String endTime) {
        return success(binancePriceMonitoringService.macd15(code, startTime, endTime));
    }
}
